
package com.probiz.estore.imports.handler.product;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.probiz.estore.common.model.product.Product;
import com.probiz.estore.imports.handler.ColumnHandler;
import com.probiz.estore.imports.handler.basic.ColumnBasicHandler;
import com.probiz.estore.imports.model.Column;
import com.probiz.estore.imports.model.ImportModel;
import com.probiz.estore.product.service.ProdMainManager;
import com.probiz.estore.product.service.ProductManager;

public class ProductNameHandler extends ColumnBasicHandler implements ColumnHandler {
	private Logger logger = Logger.getLogger(ProductNameHandler.class);
	private ProductManager productManager;
	private ProdMainManager prodMainManager;
	public void setProductManager(ProductManager productManager) {
		this.productManager = productManager;
	}
	public void setProdMainManager(ProdMainManager prodMainManager) {
		this.prodMainManager = prodMainManager;
	}


	public void setProperty(ImportModel importModel,Column column) throws Exception {
		Product product=(Product)importModel.getTarget();
		String value = column.getValue();
		if (StringUtils.isNotEmpty(value)) {
			//是导入商品和货品
			product.setProductName(value);
		}else{
			//只是导入货品
			if(!importModel.isUpdate()){
				//设置结果
				importModel.setResult(ImportModel.RESULT_ERROR);
				String msg = "无法导入，该货品所属商品并不存在，请首先导入商品";
				logger.error(msg);
				importModel.setMsg(msg);
				return;
			}
			importModel.setLevel(Integer.valueOf(2));
			product.setSkuImportFlag(true);
		}
		importModel.setResult(ImportModel.RESULT_SUCCESS);
		
	}
}
